#include "Cursor.hpp"
#include "PhoenixInitializer.hpp"

namespace phx
{

vec2i Cursor::getPosition()
{
#ifdef WIN32
	POINT p;
	GetCursorPos(&p);
	return vec2i(p.x, p.y);
#endif
}

vec2i Cursor::getPosition(phx::RenderWindow &window)
{
#ifdef WIN32
	POINT p;
	GetCursorPos(&p);
	ScreenToClient(glfwGetWin32Window(window.mGLFWwindow), &p);
	return vec2i(p.x, p.y);
#endif
}

void Cursor::setPosition(int x, int y)
{
	int windowX, windowY;
	GLFWwindow *currentWindow = glfwGetCurrentContext();
	glfwGetWindowPos(currentWindow, &windowX, &windowY);

	x -= windowX;
	y -= windowY;

	glfwSetCursorPos(currentWindow, x, y);
}

void Cursor::setPosition(vec2i &pos)
{
	int windowX, windowY;
	GLFWwindow *currentWindow = glfwGetCurrentContext();
	glfwGetWindowPos(currentWindow, &windowX, &windowY);

	pos.x -= windowX;
	pos.y -= windowY;

	glfwSetCursorPos(currentWindow, pos.x, pos.y);
}

void Cursor::setPosition(int x, int y, phx::RenderWindow &window)
{
	glfwSetCursorPos(window.mGLFWwindow, x, y);
}

void Cursor::setPosition(const vec2i &pos, phx::RenderWindow &window)
{
	glfwSetCursorPos(window.mGLFWwindow, pos.x, pos.y);
}

}